package com.test;

import be.teletask.onvif.DiscoveryManager;
import be.teletask.onvif.OnvifManager;
import be.teletask.onvif.listeners.DiscoveryListener;
import be.teletask.onvif.listeners.OnvifMediaProfilesListener;
import be.teletask.onvif.listeners.OnvifResponseListener;
import be.teletask.onvif.listeners.OnvifServicesListener;
import be.teletask.onvif.models.Device;
import be.teletask.onvif.models.OnvifDevice;
import be.teletask.onvif.models.OnvifMediaProfile;
import be.teletask.onvif.models.OnvifServices;
import be.teletask.onvif.responses.OnvifResponse;

import java.util.List;

/**
 * @Description //TODO
 * @Date 2025/7/10 9:57
 * @Author 郭建波
 **/
public class test {
    public static void main(String[] args) {

//        DiscoveryManager manager = new DiscoveryManager();
//        manager.setDiscoveryTimeout(100000);
//        manager.discover(new DiscoveryListener() {
//            @Override
//            public void onDiscoveryStarted() {
//            }
//
//            @Override
//            public void onDevicesFound(List<Device> list) {
//                for (Device device : list){
//                    System.out.println(device.getHostName());
//                }
//            }
//
//
//        });

        OnvifDevice device = new OnvifDevice("192.168.0.26", "admin", "123456");
        device.setConnected(true);
        OnvifManager onvifManager = new OnvifManager(new OnvifResponseListener() {
            public void onResponse(OnvifDevice onvifDevice, OnvifResponse onvifResponse) {
                System.out.println(onvifResponse.getXml());
            }

            public void onError(OnvifDevice onvifDevice, int errorCode, String errorMsg) {
                System.out.println("发生错误"+errorCode+":"+errorMsg);
            }
        });


//        onvifManager.getServices(device, new OnvifServicesListener() {
//            @Override
//            public void onServicesReceived( OnvifDevice onvifDevice, OnvifServices services) {
//                System.out.println(services.getPtzPath());
//                System.out.println(services.getServicesPath());
//                System.out.println(services.getMediaPath());
//            }
//        });

// 尝试使用不同的认证方式

        onvifManager.getServices(device, new OnvifServicesListener() {
            @Override
            public void onServicesReceived(OnvifDevice onvifDevice, OnvifServices services) {
                System.out.println("PTZ服务路径: " + services.getPtzPath());
                System.out.println("服务路径: " + services.getServicesPath());
                System.out.println("Media服务路径: " + services.getMediaPath());
            }
        });

//
//        onvifManager.getMediaProfiles(device, new OnvifMediaProfilesListener() {
//            @Override
//            public void onMediaProfilesReceived(OnvifDevice onvifDevice, List<OnvifMediaProfile> list) {
//                list.forEach(onvifMediaProfile -> {
//                    System.out.println(onvifMediaProfile.getToken());
//                });
//            }
//
//        });



    }

}
